# ConfigureShaders.cmake.in
#
# Generates CMAKE_CURRENT_BINARY_DIR/ConfigureShaders.cmake.
#
# Script run at build time to package Shader files into a single shader package file.
#

set(SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
set(SHADER_FILES "@SHADER_FILES@")
set(TEMPLATE_FILE "@TEMPLATE_FILE@")
set(OUTPUT_CPP_FILE "@OUTPUT_CPP_FILE@")

foreach(FILE ${SHADER_FILES})
    file(READ "${SOURCE_DIR}/${FILE}" CONTENTS)
    # Replace \n with EOL text into TEMP_STR (append a newline)
    string(REGEX REPLACE "\n" "%EOL%" TEMP_STR "${CONTENTS}\n")
    # Replace " with QUOTE into ${FILE}, used as a configure in the .in file
    string(REGEX REPLACE "\"" "%QUOTE%" ${FILE} "${TEMP_STR}")
endforeach()

# Next configure the template .in file with all of our variables
configure_file("${TEMPLATE_FILE}" "${OUTPUT_CPP_FILE}" @ONLY)
